package com.ag.hmk.action;


import java.util.List;

import com.ag.common.IDUtil;
import com.ag.common.PageUtil;
import com.ag.hmk.service.impl.HmkUiltServImpl;
import com.opensymphony.xwork2.ActionSupport;
/**
 * 
 * @author hmk
 * 查询队伍列表（分页查询）
 */
public class FindSomeTeamAction extends ActionSupport {
	private static final long serialVersionUID = -4270657116058210604L;
	
	private HmkUiltServImpl hmkUiltServImpl;
	private int page;
	private int maxRow;
	private String wukuType;
	private String teamName;
	private String teamLocaton;
	
	private PageUtil pageUtil; //返回结果
	
	/*
	 * 查询队伍列表（分页查询）
	 */
	public String findTeamList()throws Exception{
		PageUtil pUtil = new PageUtil();
		List result=null;
		int total=0;
		try {
			String cql = "select count(t.teamId) from TbTeam t where 1=1";
			String hql = "select t from TbTeam t left join fetch t.tbType where 1=1";
			System.out.println("----"+wukuType);
			if (wukuType!=null && wukuType.length()>0) {
				cql += " and t.tbType.tpyeId = " + wukuType;
				hql += " and t.tbType.tpyeId = " + wukuType;
			}
			System.out.println("----"+teamName);
			if (teamName!=null && teamName.length()>0) {
				cql += " and t.teamName like '%" + teamName+"%'";
				hql += " and t.teamName like '%" + teamName+"%'";
			}
			System.out.println("----"+teamLocaton);
			if (teamLocaton!=null && teamLocaton.length()>0) {
				cql += " and t.teamLocation like '%" + teamLocaton+"%'";
				hql += " and t.teamLocation like '%" + teamLocaton+"%'";
			}
			cql+=" and t.a='"+IDUtil.PRESERVE+"' ";
			hql+=" and t.a='"+IDUtil.PRESERVE+"' order by t.teamId desc";
			//查询条数
			total = hmkUiltServImpl.getCount(cql);
			if (page == 0) {
				page = 1;
			}
			if (maxRow == 0) {
				maxRow = 10;
			}
			int firstRow = (page - 1) * maxRow;
			//分页查询
			result = hmkUiltServImpl.query(hql, firstRow, maxRow);
		} catch (Exception e) {
			e.printStackTrace();
			result=null;
			total=0;
		}
		
		pUtil.setTotal(total);
		pUtil.setPage(page);
		pUtil.setMaxRow(maxRow);
		pUtil.setList(result);
		
		this.setPageUtil(pUtil);
		return "findTeamListOK";
	}

	public void setHmkUiltServImpl(HmkUiltServImpl hmkUiltServImpl) {
		this.hmkUiltServImpl = hmkUiltServImpl;
	}



	public void setWukuType(String wukuType) {
		this.wukuType = wukuType;
	}


	public void setTeamName(String teamName) {
		this.teamName = teamName;
	}


	public void setTeamLocaton(String teamLocaton) {
		this.teamLocaton = teamLocaton;
	}





	public PageUtil getPageUtil() {
		return pageUtil;
	}


	public void setPageUtil(PageUtil pageUtil) {
		this.pageUtil = pageUtil;
	}


	public void setPage(int page) {
		this.page = page;
	}


	public void setMaxRow(int maxRow) {
		this.maxRow = maxRow;
	}

	
	

}
